Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | 3x 3x 3x 3x 3x 1x 2x 3x 3x 3x 3x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x | import { Metadata } from "next";
import { draftMode } from "next/headers";
import { notFound } from "next/navigation";
import { formatDate, calculateReadingTime} from "@/lib/utils";
import RenderMarkdown from "@/components/custom/RenderMarkdown";
import { StrapiImage } from "@/components/custom/strapi-image";
import { getBlogPostBySlug } from "@/data/loaders";
import { BlockRenderer } from "@/components/block-renderer";
import ReadingProgress from "@/components/ui/ReadingProgress";
import { CkeditorBlock } from "@/components/block-renderer/layout/ckeditor-block";
import TableOfContents from "@/components/custom/TableOfContents";
import { generateMetadataObject } from '@/lib/metadata';
import fetchContentType from '@/lib/strapi/fetchContentType';
import { strapiImage } from '@/lib/strapi/strapiImage';
import RelatedPosts from "@/components/custom/related-posts";
import SocialShareButtons from "@/components/custom/SocialShareButtons";
import Image from "next/image";
import DisqusComments from "@/components/custom/DisqusComments";
import { FiEye, FiArrowLeft } from "react-icons/fi";
import Link from "next/link";
interface PageProps {
params: Promise<{ slug: string }>;
}
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
const BASE_URL_NEXT = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
const resolveParams = await params;
const slug = await resolveParams?.slug;
const pageData = await fetchContentType('posts', {
filters: { slug: slug }, // Filter by slug
populate: ["category","seo.metaImage","image"],
}, true)
//console.log("Page Data:", pageData); // Debugging output
if (!pageData) {
return {
title: "Blog Not Found | Bitmutex Technologies",
description: "The requested blog/article does not exist. Browse more blogs by Bitmutex Technologies.",
robots: "noindex, nofollow", // Avoid indexing non-existent pages
};
}
const seo = pageData?.seo;
const metadata = generateMetadataObject(seo);
// ✅ Ensure title fallback to `pageData.title` if `seo.metaTitle` is missing
const seotitle = seo?.metaTitle
? `${seo.metaTitle} | ${pageData.category?.text || "Uncategorized"} | Bitmutex Blogs`
: `${pageData.title || "Untitled"} | ${pageData.category?.text || "Uncategorized"} |Bitmutex Blogs`;
// ✅ use pageData description as fallback if metaDescription is not available
let seodescription = seo?.metaDescription || pageData.description || "";
Iif (seodescription.length > 150) {
seodescription = seodescription.substring(0, seodescription.lastIndexOf(" ", 150)) + "...";
}
// ✅ Override normal title field
metadata.title = seotitle;
metadata.description = seodescription;
// ✅ Override OG fields
metadata.openGraph = {
...(metadata.openGraph as any), // Cast to 'any' to allow unknown properties
title: seotitle,
description: seodescription,
images: seo?.metaImage
? [{ url: strapiImage(seo?.metaImage.url) }]
: pageData?.image
? [{ url: strapiImage(pageData.image.url) }]
: [],
url: `${BASE_URL_NEXT}/blog/${slug}`, // Add custom URL field
site_name: "Bitmutex",
locale: "en_US",
type: "article",
};
// ✅ Assign canonical URL to `alternates`
metadata.alternates = {
canonical: `${BASE_URL_NEXT}/blog/${slug}`,
};
return metadata;
}
export default async function SinglePost({ params }: PageProps) {
const resolveParams = await params;
const slug = resolveParams?.slug;
const { isEnabled: isDraftMode } = await draftMode();
const status = isDraftMode ? "draft" : "published";
const data = await getBlogPostBySlug(slug, status);
const post = data?.data[0];
console.log('post data is ', post);
if (!post) notFound();
const blocks = post?.blocks || [];
const fullContent = `${post.content || ""} ${post.content1 || ""} ${post.content2 || ""}`;
const readingTime = fullContent.trim() ? calculateReadingTime(fullContent) : 1;
const viewCount = post.views || 0; // Assuming views are coming from API
// Social share URLs
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:1337"; // Fallback URL
const shareUrl = encodeURIComponent(`${baseUrl}/blog/${slug}`);
const shareText = encodeURIComponent(`Check out our latest blog post:\n\n"${post.title}"\n\nRead more below:`);
const twitterShare = `https://twitter.com/intent/tweet?url=${shareUrl}&text=${shareText}`;
const facebookShare = `https://www.facebook.com/sharer/sharer.php?u=${shareUrl}`;
const linkedinShare = `https://www.linkedin.com/shareArticle?mini=true&url=${shareUrl}&text=${shareText}`;
const redditShare = `https://www.reddit.com/submit?url=${shareUrl}&title=${shareText}`;
const whatsappShare = `https://api.whatsapp.com/send?text=${shareText}%20${shareUrl}`;
return (
<article className="pt-10 pb-16">
<ReadingProgress />
<TableOfContents containerClass="post-content" />
<div className="container max-w-8xl px-4">
{/* Back to All Blogs Button */}
<div className="pt-6 pb-2">
<Link
href="/blog"
className="inline-flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-neutral-800 hover:text-gray-900 dark:hover:text-gray-100 transition-all w-fit"
>
<FiArrowLeft size={16} />
<span>Back to all blogs</span>
</Link>
</div>
<header className="my-10 text-center">
<h1 className="font-heading text-4xl font-extrabold tracking-tight sm:text-5xl mb-4">
{post.title}
</h1>
{/* Author Info Section */}
{post.author && (
<div className="mt-6 mb-4 flex items-center justify-center space-x-4 border-t pt-4">
{/* Author Image (if available) */}
{post.author.image?.url ? (
<Image
src={post.author.image.url}
alt={post.author.image.alternativeText || post.author.firstname}
width={56} // Corresponds to w-14
height={56} // Corresponds to h-14
className="w-14 h-14 rounded-full object-cover border border-gray-300 dark:border-gray-700 shadow-sm"
/>
) : (
<div className="w-14 h-14 rounded-full bg-gray-200 dark:bg-gray-700 flex items-center justify-center text-gray-600 dark:text-gray-300 text-lg font-semibold">
{post.author.firstname.charAt(0)}
{post.author.lastname.charAt(0)}
</div>
)}
{/* Author Details */}
<div>
<p className="font-heading text-gray-900 dark:text-gray-100 font-semibold text-lg">
{post.author.firstname} {post.author.lastname}
</p>
{post.author.email && (
<a
href={`mailto:${post.author.email}`}
className="font-sans text-blue-600 dark:text-orange-400 text-sm hover:underline transition duration-200"
>
{post.author.email}
</a>
)}
</div>
</div>
)}
<p className="text-gray-500 dark:text-gray-400 text-sm">
Posted on {formatDate(post.publishedAt)} • {post.category.text} • {" "}
<span className="font-semibold">{readingTime} min read</span>
</p>
{/* View Count */}
<div className="flex justify-center mt-4">
<div className="inline-flex items-center gap-1.5 px-3 py-1 bg-gray-100/80 dark:bg-neutral-800/50 border border-gray-200/60 dark:border-neutral-700/60 rounded-full text-sm font-medium text-gray-600 dark:text-gray-300 shadow-sm transition-colors hover:bg-gray-200/80 dark:hover:bg-neutral-800/80">
<FiEye size={15} className="text-gray-500 dark:text-gray-400" />
<span>{viewCount} views</span>
</div>
</div>
{/* Share Buttons */}
<div className="flex justify-center gap-4 mt-4">
<SocialShareButtons slug={slug} title={post.title} />
</div>
<StrapiImage
src={post.image.url}
alt={post.image?.alternativeText || "Bitmutex Blog Post Image"}
width={800}
height={600}
priority
className="w-full max-w-sm sm:max-w-2xl lg:max-w-5xl h-56 sm:h-72 md:h-80 lg:h-125 xl:h-137.5 mx-auto mt-4 mb-4 sm:mt-6 sm:mb-6 lg:mt-8 lg:mb-8 rounded-lg sm:rounded-xl lg:rounded-2xl shadow-lg sm:shadow-xl lg:shadow-2xl object-fill transition-all duration-300 sm:duration-500 lg:duration-700 hover:scale-102 sm:hover:scale-105 hover:shadow-xl sm:hover:shadow-2xl lg:hover:shadow-[0_25px_50px_-12px_rgba(0,0,0,0.5)] hover:brightness-105 sm:hover:brightness-110 filter"
/>
</header>
{/* Post Content START */}
<div className="post-content">
<section className="flex items-center justify-center md:px-1 md:py-1">
<div className="full-width-element relative w-full bg-white dark:bg-neutral-950 md:max-w-7xl md:rounded-2xl md:shadow-lg md:p-10 md:border dark:md:border-gray-700 transition-all">
{/* Accent Gradient Border */}
<div className="absolute top-0 left-0 w-full h-2 bg-linear-to-r from-orange-500 via-yellow-400 to-orange-500 rounded-t-2xl"></div>
{/* The rest of the content */}
<div className="rich-text prose max-w-none text-gray-800 dark:text-gray-200 leading-relaxed">
{/* The content rendering logic */}
{post.content && (
<div className="mb-8">
<RenderMarkdown content={post.content} />
</div>
)}
{post.content1 && (
<div className="mb-8">
<RenderMarkdown content={post.content1} />
</div>
)}
{post.content2 && (
<div className="mb-8">
<CkeditorBlock content={post.content2} />
</div>
)}
</div>
</div>
</section>
</div>
{/* Post Content END */}
{/* Dynamic Content Blocks */}
{blocks && (
<div className="mt-6">
<BlockRenderer blocks={blocks} />
</div>
)}
</div>
<div className="container max-w-8xl px-4">
{/*Related Posts */}
<RelatedPosts category={post.category}/>
{/* Disqus Comments Section using disqus-react */}
<DisqusComments post={{ slug: post.slug, title: post.title }} />
</div>
</article>
);
} |